package com.mask.im.business.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mask.im.business.model.dto.ChatHistoryDTO;
import com.mask.im.business.model.dto.AdminChatMessageDTO;
import com.mask.im.business.model.entity.chat.IMFriendChatMessageDO;
import com.mask.im.business.model.vo.IMChatMessageQuotedVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;


/**
 * 好友聊天记录
 *
 * @author jian
 */
@Mapper
@Repository
public interface IMFriendChatMessageMapper extends BaseMapper<IMFriendChatMessageDO> {

    IMChatMessageQuotedVO selectQuoteChatMessage(@Param("messageId") Integer messageId);

    /**
     * 批量更新消息已读状态
     *
     * @param messageIds 消息ID列表
     * @param userId     当前用户ID（接收方）
     * @param friendId   好友ID（发送方）
     * @param isRead     已读状态 1-已读 0-未读
     * @param readTime   已读时间
     * @return 更新数量
     */
    int batchUpdateReadStatus(
            @Param("messageIds") List<Integer> messageIds,
            @Param("userId") Integer userId,
            @Param("friendId") Integer friendId,
            @Param("isRead") Integer isRead,
            @Param("readTime") LocalDateTime readTime);

    ;

    List<IMFriendChatMessageDO> selectChatMessages(@Param("userId") Long userId,
                                                 @Param("friendId") Long friendId,
                                                 @Param("page") Integer page,
                                                 @Param("size") Integer size);

    List<ChatHistoryDTO> getChatRecords(@Param("userId") Integer userId);

    Integer chatRecordCount(@Param("userId") Integer userId);

    Integer selectChatListCount(@Param("sender") String sender,
                                @Param("receiver") String receiver);

    List<AdminChatMessageDTO> selectChatList(
            @Param("sender") String sender,
            @Param("receiver") String receiver,
            @Param("currentPage") long currentPage,
            @Param("size") long size);

    IMFriendChatMessageDO maxChatMessageId(@Param("userInfoId") Long userInfoId,
                                         @Param("friendId") Long friendId);

    IMFriendChatMessageDO maxNoDeletedChatMessageId(@Param("userInfoId") Long userInfoId,
                                                  @Param("friendId") Long friendId);
}

